/**
 * 双指针-牛逼的那版
 * @param {number[]} nums
 * @return {number[]}
 */
var sortedSquares = function (nums) {
    let left = 0,
        nLen = nums.length,
        res = new Array(nLen),
        right = nLen - 1

    while (left <= right) {
        if (nums[left] * nums[left] <= nums[right] * nums[right]) {
            res[--nLen] = nums[right] * nums[right]
            right--
        } else {
            res[--nLen] = nums[left] * nums[left]
            left++
        }
    }
    return res
};

console.log(sortedSquares([-4, -1, 0, 1, 3, 10]))